package com.example.lin.generate;

import com.example.lin.util.ImportUtil;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @className: ReadTextComparison
 * @description: 读取 Excel文本对比操作
 * @author: Lin.Gu
 * @date: 2025/5/15
 */
public class ReadTextComparison {

    @Test
    public void readTextComparisonTest() {
        System.out.println("开始读取");
        long start = System.currentTimeMillis();
        String filePath = "C:\\Users\\181596\\Desktop\\数据信息.xlsx";
        //旧数据
        List<List<Object>> oldList = ImportUtil.readExcelToList(filePath, 0);
        System.out.println("读取完成-oldList");

        Set<String> checkSet = new HashSet<>();

        for (List<Object> objectList : oldList) {
            String v1 = (String) objectList.get(0);
            String v2 = (String) objectList.get(1);

            String key = v1 + v2;
            if (checkSet.contains(key)) {
                System.out.println(key);
            } else {
                checkSet.add(key);
            }
        }
//        //新数据
//        List<List<Object>> newList = ImportUtil.readExcelToList(filePath, 1);
//        System.out.println("读取完成-newList");

        // 1. 完全不重复的子列表
//        List<List<Object>> onlyInOld = new ArrayList<>(oldList);
//        onlyInOld.removeIf(newList::contains);

//        StringBuffer line = new StringBuffer();
//        for (List<Object> objects : onlyInOld) {
//            line.append(objects.get(0)).append("\n");
//        }
//        System.out.println(line);
//        List<Object> sqlList = new LinkedList<>();
//        for (List<Object> objects : onlyInOld) {
//            sqlList.add(objects.get(0));
//        }
//        ExportUtil.writeDataToFile(sqlList, "核对数据多余的信息记录");
        System.out.println("处理完成:" + (System.currentTimeMillis() - start) / 1000 + "s");
    }

    /**
     * 标题: 读取文本对比
     * tracking_number,transaction_id,sku_value,quantity
     * 读取SKU信息 并判断是否大于1 如果不大于 补成1 并生成脚本信息
     */
    @Test
    public void readSku() {
        System.out.println("开始读取");
        long start = System.currentTimeMillis();
        String filePath = "C:\\Users\\181596\\Desktop\\数据信息.xlsx";
        List<List<Object>> oldList = ImportUtil.readExcelToList(filePath, 0);
        System.out.println("读取完成");

        String template = "";

        for (List<Object> objValue : oldList) {
            String trackingNumber = (String) objValue.get(0);
            String transactionId = (String) objValue.get(1);
            //String skuValue = (String) objValue.get(2);
            String quantity = (String) objValue.get(3);

            BigDecimal skuValue = new BigDecimal(1);
            if (Integer.parseInt(quantity) > 1) {
                skuValue = BigDecimal.valueOf(1).divide(new BigDecimal(quantity));
            }
        }
    }

}
